-
-
Notifications
You must be signed in to change notification settings - Fork 304
[changhyumm] WEEK 02 solutions #2070
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
seungriyou
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이번 한 주도 수고 많으셨습니다~~! 🦾
| l += 1 | ||
| r -= 1 | ||
| return list(ans_set) | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
파일 마지막에 빈 개행이 한 줄만 들어가도록 수정 부탁드립니다~!
| answer = [] | ||
| for k in range(len(left)): | ||
| answer.append(left[k]*right[k]) | ||
| return answer No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merge를 위해 파일 마지막에 빈 개행 추가 부탁드립니다!
|
|
||
|
|
||
| ## 투포인터 활용 | ||
| # sort + loop -> O(nlogn) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sort + 이중 loop이므로 시간 복잡도가 O(n^2)이 될 것 같습니다!
| r -= 1 | ||
| else: | ||
| # 중복제거 | ||
| ans_set.add((nums[i], nums[l], nums[r])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set을 활용해 중복 제거를 하셨네요! 저는 포인터 기반으로 루프 내에서 중복을 제거하도록 풀어봤었는데, 이렇게 하면 set을 유지하기 위한 추가적인 공간 복잡도를 최적화 할 수 있더라구요! 한 번 포인터 기반으로도 풀어보시는 걸 추천드립니다~~ 🤩
| dp[1] = 2 | ||
|
|
||
| for i in range(2, n): | ||
| dp[i] = dp[i-2] + dp[i-1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이렇게 DP 테이블의 가장 최근 n개의 원소만 사용하는 경우에는 O(n) space의 DP 테이블 대신 O(1)space의 변수를 사용해서 공간 복잡도를 한 단계 최적화 할 수 있을 것 같아요~!
| else: | ||
| return False | ||
| # 시간복잡도 O(n) | ||
| # 공간복잡도 O(n) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저도 다시 풀어보면서 알게 된 사실인데요, 이 문제에서는 입력값이 모두 영어 소문자로만 구성되어 있으므로 공간 복잡도가 O(26) = O(1)이 된다고 합니다!
| for char in t: | ||
| if char in counter and counter[char] != 0: | ||
| counter[char] -= 1 | ||
| elif char in counter and counter[char] == 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if-elif 문에서 char in counter 확인 로직이 중복되므로 이를 분리한다면 코드가 조금 더 단순해질 것 같습니다!
답안 제출 문제
작성자 체크 리스트
In Review로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!